package com.rayn.test;

import com.rayn.mediainfo.jna.MediaInfo;
import org.junit.Before;
import org.junit.Test;

import java.io.IOException;

/**
 * Created by Administrator on 2015/1/23.
 */
public class ParseMediaProperties
{

    @Before
    public void init() throws Exception
    {
//        File file = new File("D:/1.gif");
//        FileInputStream fis = new FileInputStream(file);
//        BufferedImage buff = ImageIO.read(fis);
//
//        System.out.println(buff.getWidth());
//        System.out.println(buff.getHeight());

    }

    @Test
    public void testFileProperties1() throws IOException
    {
        MediaInfo mediaInfo = new MediaInfo();

        mediaInfo.Open("F:/1.flv");
//        Map<MediaInfo.StreamKind, List<Map<String, String>>> params = mediaInfo.(file);
//
//        for(Map.Entry<MediaInfo.StreamKind, List<Map<String, String>>> entry : params.entrySet())
//        {
//            System.out.println(entry.getKey());
//            System.out.println(entry.getValue());
//            System.out.println("************************************************************");
//        }

        String info = mediaInfo.Get(MediaInfo.StreamKind.Video, 0, "StreamCount", MediaInfo.InfoKind.Text, MediaInfo.InfoKind.Name);
        System.out.println(info);
        /**
         * 获取视频的宽度和高度
         */
        System.out.println("***********************************************************");
        String type = mediaInfo.Get(MediaInfo.StreamKind.General, 0, "FileExtension", MediaInfo.InfoKind.Text);
        String width = mediaInfo.Get(MediaInfo.StreamKind.Video, 0, "Width", MediaInfo.InfoKind.Text);
        String height = mediaInfo.Get(MediaInfo.StreamKind.Video, 0, "Height", MediaInfo.InfoKind.Text);
        System.out.println(type);
        System.out.println(width);
        System.out.println(height);
    }

    @Test
    public void testFileProperties() throws IOException
    {
        String To_Display = "";

        //Info about the library

        To_Display += MediaInfo.Option_Static("Info_Version");

        To_Display += "\r\n\r\nInfo_Parameters\r\n";
        To_Display += MediaInfo.Option_Static("Info_Parameters");

        To_Display += "\r\n\r\nInfo_Capacities\r\n";
        To_Display += MediaInfo.Option_Static("Info_Capacities");

        To_Display += "\r\n\r\nInfo_Codecs\r\n";
        To_Display += MediaInfo.Option_Static("Info_Codecs");

        //An example of how to use the library

        MediaInfo MI = new MediaInfo();

        String fileName = "F:/1.flv";


        To_Display += "\r\n\r\nOpen\r\n";
        if (MI.Open(fileName)>0)
            To_Display+="is OK\r\n";
        else
            To_Display+="has a problem\r\n";

//        To_Display += "\r\n\r\nInform with Complete=false\r\n";
//        MI.Option("Complete", "");
//        To_Display += MI.Inform();

        To_Display += "\r\n\r\nInform with Complete=true\r\n";
        MI.Option("Complete", "1");
        To_Display += MI.Inform();

//        To_Display += "\r\n\r\nCustom Inform\r\n";
//        MI.Option("Inform", "General;Example : FileSize=%FileSize%");
//        To_Display += MI.Inform();
//
//        To_Display += "\r\n\r\nGetI with Stream=General and Parameter=2\r\n";
//        To_Display += MI.Get(MediaInfo.StreamKind.General, 0, 2, MediaInfo.InfoKind.Text);
//
//        To_Display += "\r\n\r\nCount_Get with StreamKind=Stream_Audio\r\n";
//        To_Display += MI.Count_Get(MediaInfo.StreamKind.Audio, -1);

//        To_Display += "\r\n\r\nGet with Stream=General and Parameter=\"AudioCount\"\r\n";
//        To_Display += MI.Get(MediaInfo.StreamKind.General, 0, "AudioCount", MediaInfo.InfoKind.Text, MediaInfo.InfoKind.Name);

        To_Display += "\r\n\r\nGet with Stream=Audio and Parameter=\"StreamCount\"\r\n";
        To_Display += MI.Get(MediaInfo.StreamKind.Audio, 0, "StreamCount", MediaInfo.InfoKind.Text, MediaInfo.InfoKind.Name);


//        To_Display += "\r\n\r\nGet with Stream=General and Parameter=\"FileSize\"\r\n";
//        To_Display += MI.Get(MediaInfo.StreamKind.General, 0, "FileSize", MediaInfo.InfoKind.Text, MediaInfo.InfoKind.Name);

        To_Display += "\r\n\r\nClose\r\n";
        MI.Close();

        System.out.println(To_Display);
    }

}
